package com.cardone.platform.configuration.utils;

import lombok.NonNull;

import org.apache.commons.lang.StringUtils;

import com.cardone.context.ContextHolder;
import com.cardone.persistent.CommonDtoAttributes;
import com.cardone.platform.configuration.dto.DictionaryDto;
import com.cardone.platform.configuration.service.DictionaryService;

/**
 * 字典工具类
 * 
 * @author yaoht
 * 
 */
public class DictionaryUtils {
	/**
	 * 查询:字典
	 * 
	 * @param typeCode
	 *            类别编号
	 * @param code
	 *            编号
	 * @return 字典
	 */
	public static DictionaryDto findDictionaryByTypeCodeAndCode(@NonNull final String typeCode, @NonNull final String code) {
		final DictionaryDto dictionary = ContextHolder.getBean(DictionaryService.class).findDictionaryByTypeCodeAndCode(typeCode, code);

		return dictionary;
	}

	/**
	 * 读取：字典标识
	 * 
	 * @param typeCode
	 *            类别编号
	 * @param code
	 *            编号
	 * 
	 * @return 返回值
	 */
	public static String readDictionaryIdByTypeCodeAndCode(@NonNull final String typeCode, @NonNull final String code) {
		final String dictionaryId = ContextHolder.getBean(DictionaryService.class).readDictionaryByTypeCodeAndCode(String.class,
		        CommonDtoAttributes.id.name(), StringUtils.EMPTY, typeCode, code);

		return dictionaryId;
	}

	/**
	 * 读取：字典标识
	 * 
	 * @param defaultValue
	 *            默认值
	 * @param typeCode
	 *            类别编号
	 * @param code
	 *            编号
	 * 
	 * @return 返回值
	 */
	public static String readDictionaryIdByTypeCodeAndCode(@NonNull final String defaultValue, @NonNull final String typeCode,
	        @NonNull final String code) {
		final String dictionaryId = ContextHolder.getBean(DictionaryService.class).readDictionaryByTypeCodeAndCode(String.class,
		        CommonDtoAttributes.id.name(), defaultValue, typeCode, code);

		return dictionaryId;
	}

	/**
	 * 读取：字典名称
	 * 
	 * @param typeCode
	 *            类别编号
	 * @param code
	 *            编号
	 * 
	 * @return 返回值
	 */
	public static String readDictionaryNameByTypeCodeAndCode(@NonNull final String typeCode, @NonNull final String code) {
		final String dictionaryCode = ContextHolder.getBean(DictionaryService.class).readDictionaryByTypeCodeAndCode(String.class,
		        CommonDtoAttributes.name.name(), StringUtils.EMPTY, typeCode, code);

		return dictionaryCode;
	}

	/**
	 * 读取：字典名称
	 * 
	 * @param defaultValue
	 *            默认值
	 * @param typeCode
	 *            类别编号
	 * @param code
	 *            编号
	 * 
	 * @return 返回值
	 */
	public static String readDictionaryNameByTypeCodeAndCode(@NonNull final String defaultValue, @NonNull final String typeCode,
	        @NonNull final String code) {
		final String dictionaryCode = ContextHolder.getBean(DictionaryService.class).readDictionaryByTypeCodeAndCode(String.class,
		        CommonDtoAttributes.name.name(), defaultValue, typeCode, code);

		return dictionaryCode;
	}

	/**
	 * 读取：字典值
	 * 
	 * @param typeCode
	 *            类别编号
	 * @param code
	 *            编号
	 * 
	 * @return 返回值
	 */
	public static String readDictionaryValueByTypeCodeAndCode(@NonNull final String typeCode, @NonNull final String code) {
		final String dictionaryValue = ContextHolder.getBean(DictionaryService.class).readDictionaryByTypeCodeAndCode(String.class,
		        CommonDtoAttributes.value.name(), StringUtils.EMPTY, typeCode, code);

		return dictionaryValue;
	}

	/**
	 * 读取：字典值
	 * 
	 * @param defaultValue
	 *            默认值
	 * @param typeCode
	 *            类别编号
	 * @param code
	 *            编号
	 * 
	 * @return 返回值
	 */
	public static String readDictionaryValueByTypeCodeAndCode(@NonNull final String defaultValue, @NonNull final String typeCode,
	        @NonNull final String code) {
		final String dictionaryValue = ContextHolder.getBean(DictionaryService.class).readDictionaryByTypeCodeAndCode(String.class,
		        CommonDtoAttributes.value.name(), defaultValue, typeCode, code);

		return dictionaryValue;
	}
}
